

import request from '@/utils/request'
import { removeToken, setToken } from '@/utils/token';
import { LOGIN, LOGOUT } from '../constants';
/**
 * 
 * @param {*} mobile 
 * @param {*} code 
 * @returns 
 */
export const login = (mobile, code) => {
    return async (dispatch) => {
        const res = await request.post('/authorizations', { mobile, code })
        const token = res.data.data.token
        // 本地也存储一份
        setToken(token)
        dispatch({
            type: LOGIN,
            payload: token
        })
    }
}

export const logout = () => {
    // 清楚本地token
    removeToken()
    return {
        type: LOGOUT
    }
}